package com.itheima.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.domain.EmpQueryParam;
import com.itheima.domain.PageResult;
import com.itheima.domain.Result;
import com.itheima.domain.StudentsQueryParam;
import com.itheima.domain.pojo.Students;
import com.itheima.mapper.StudentsMapper;
import com.itheima.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class StudentsServiceImpl implements StudentsService {

    @Autowired
    private StudentsMapper studentsMapper;


    @Override
    public PageResult<Students> StudentsList(StudentsQueryParam studentsQueryParam) {
        //1.获取分页参数
        PageHelper.startPage(studentsQueryParam.getPage(),studentsQueryParam.getPageSize());
        //2.调用方法
        List<Students>empList= studentsMapper.SelectStudentsList(studentsQueryParam);
        Page<Students>p=(Page<Students>) empList;
        return  new PageResult(p.getTotal(),p.getResult());
    }

    @Override
    public void delete(List<Integer> ids) {
        studentsMapper.delete(ids);
    }

    @Override
    public void save(Students students) {
        students.setCreateTime(LocalDateTime.now());
        students.setUpdateTime(LocalDateTime.now());
        studentsMapper.insert(students);
    }

    @Override
    public Students selectByStudentId(Integer id) {
        studentsMapper.selectByStudentId(id);
        return studentsMapper.selectByStudentId(id);

    }

    @Override
    public void update(Students students) {
        students.setUpdateTime(LocalDateTime.now());
        studentsMapper.update(students);

    }

    @Override
    public void violation(Integer id, Integer score) {
        studentsMapper.violation(id,score);
    }

//    @Override
//    public List<Students> studentlists() {
//        return studentsMapper.studentlists();
//    }
}
